<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>后台管理</title>
		<link rel="stylesheet" type="text/css" href="../../backstagestatic/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../backstagestatic/admin/css/admin.css" />
	</head>

	<body>
		<div class="page-content-wrap">
			<form id="form1">
				<input type="hidden" name="">
			</form>
				<form class="layui-form" action="">	
						<div class="layui-form-item">
							<div class="layui-inline tool-btn">
								<button class="layui-btn layui-btn-small layui-btn-normal addBtn hidden-xs" data-url="book-add.html"><i class="layui-icon">&#xe654;</i></button>
							</div>
							<div class="layui-inline">
								<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-inline">
								<select name="states" lay-filter="status">
									<option value="">请选择一个分类</option>
									<option value="01">人文</option>
									<option value="02">儿童</option>
									<option value="03">教育</option>
									<option value="04">文艺</option>
								</select>
							</div>
							<button class="layui-btn layui-btn-normal" lay-submit="search">搜索</button>
						</div>
					</form>
					<div class="layui-form" id="table-list">
						<table class="layui-table" id="display" lay-skin="line">
							<colgroup>
								<col width="50">
								<col class="hidden-xs" width="30">
								<col class="hidden-xs" width="300">
								<col class="hidden-xs" width="100">
								<col>
								<col width="80">
								<col width="130">
							</colgroup>
							<thead>
								<tr>
									<th>
										<input type='checkbox' name='' lay-skin='primary' lay-filter='allChoose'>
									</th>
									<th class='hidden-xs'>ID</th>
									<th class='hidden-xs'>书籍名称</th>
									<th>分类</th>
									<th>数量 </th>
									<th>价格</th>
									<th>作者</th>
									<th>出版社</th>
									<th>出版时间</th>
									<th>操作</th>
								</tr> 
							</thead>
							<!--<tbody>
								<tr>
									<td>
										<input type='checkbox' name='' lay-skin='primary' data-id='1'>
									</td>
									<td class="hidden-xs">1</td>
									<td class="hidden-xs">Admin</td>
									<td>儿童</td>
									<td>pp</td>
									<td>aa</td>
									<td>aaaa</td>
									<td>1</td>
									<td>
										<div class="layui-inline">
											<button class="layui-btn layui-btn-mini layui-btn-danger del-btn" data-id="1" data-url="menu-add.html"><i class="layui-icon">&#xe640;</i></button>
										</div>
									</td>
								</tr>
								
							</tbody> -->
						</table>
					</div>
		</div>
		<script src="../../js/jquery.min.js"></script>
		<script src="../../backstagestatic/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../backstagestatic/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script>
        layui.use('element', function(){
            $(document).ready(function() {
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类
                    url: "/clerk" ,//url
                    data: $('#form1').serialize(),
                    success: function (result) {
                        var Books=result.books;
                        var str="";
                        str+="<tbody>";
                        for(var i=0;  i <Books.length; i++){
                            str+="<tr>";
                            str+="<td><input type='checkbox' name= '' lay-skin='primary' data-id="+i+"></td>";
                            str+="<td class='hidden-xs'>"+Books[i].id+"</td>";
                            str+="<td class='hidden-xs'>"+Books[i].name+"</td>";
                            str+="<td>"+Books[i].type+"</td>";
                            str+="<td>"+Books[i].inventory+"</td>";
                            str+="<td>"+Books[i].price+"</td>";
                            str+="<td>"+Books[i].author+"</td>";
                            str+="<td>"+Books[i].press+"</td>";
                            str+="<td>"+Books[i].publication+"</td>";
                            str+="<td><div class='layui-inline'><button class='layui-btn layui-btn-mini layui-btn-danger del-btn' data-id='"+Books[i].id+"'data-url='' id='off'><i class='layui-icon'>&#xe640;</i></button></div></td>";
                            str+="</tr>";
                        }
                        str+="</tbody>";
                        $("#display").append(str);

                    }
                });
                return false;
            });



            $('.del-btn').click(function() {
                dialog.confirm({
                    message:'您确定要删除选中项',
                    success:function(){

                        var That = $(this);
                        var id = That.attr('data-id');
                        var data=[];
                        data.push({"bookId":id});
                        console.log(data);
                        $.ajax({
                            type: "POST",//方法类型
                            dataType: "json",//预期服务器返回的数据类
                            url: "/bookOut",//url
                            data: JSON.stringify(data),
                            success: function () {
                                alert("删除成功");
                                table.reload();
                            }
                        });
                        layer.msg('删除了')

                    },
                    cancel:function(){
                        layer.msg('取消了')
                    }
                });
                return false;
            });
        });

	</script>
	</body>

</html>